//点击查看大图
$('.img').click(function () {
    var src = $(this).attr("src");
    var preview = $(window.parent.document).find("#preview");
    preview.find('img').attr('src', src);
    var H = Math.round(preview.height() / 2);
    preview.css({'margin-top': -H}).show();
});
//点击定标
var choosedcop = new Array();
var purchaseid = new Array();
var materielid = new Array();
var allprice;
$('#particulars>button').click(function () {
    var li = $("#table li");
    var long = li.find("input:radio:checked").length;
    console.log(li.length);
    if($('#table table').length==0){
        $("body", parent.document).find('#vague').show();
        $("body", parent.document).find('#hint').text("暂无报价！"); 
    }else{
    if (long == 0) {
        $("body", parent.document).find('#vague').show();
        $("body", parent.document).find('#hint').text("请选择！");
    } else {
        for (var i = 1; i <= long; i++) {
            var choose = li.eq(i).find("input:radio:checked").parent().parent().parent();
            var corpname = choose.find(".corpname").attr("choose");
            choosedcop[i - 1] = choose.find(".corpname").attr("chooses");
            allprice = parseFloat(choose.find(".price").attr("choose")) * li.eq(i).find(".sl").text() + parseFloat(choose.find(".freight").attr("choose"));

            var materielname = li.eq(i).find(".wl").text();
            materielid[i - 1] = li.eq(i).find(".wl").attr("choose");
            purchaseid[i - 1] = li.eq(i).find(".wl").attr("chooses");
            $('#particulars').hide();
            $('#publish').show();
            var tr = $('#publish table tbody');
            tr.append("<tr><td>" + materielname + "</td><td >" + corpname + "</td><td>" + allprice + "</td></tr>");
            allprice += allprice;
        }
    }}
});
$('#publish button').click(function () {
    var long = choosedcop.length;
    for (var i = 0; i < long; i++) {
        new Ajax("/my/my_project_back.jsp").keyvalue("totalcost", allprice).keyvalue("choosedcop", choosedcop[i]).keyvalue("purchaseid", purchaseid[i]).keyvalue("materielid", materielid[i]).getJson(function (data) {
            if (data == 1) {
                $("body", parent.document).find('#vague').show();
                $("body", parent.document).find('#hint').text("恭喜定标成功！");
                document.location = "/my/enquiry.jsp";
            } else {
                $("body", parent.document).find('#vague').show();
                $("body", parent.document).find('#hint').text("定标失败！");
            }
        })
    }
})
window.onload = function () {
    if ($("body").attr("marker") == 1) {
        $("#particulars").show();
        $("#result").hide();
    } else {
        $("#particulars").hide();
        $("#result").show();
    }
    if($("#particulars button").attr("marker")==0){
        $("#particulars button").hide();
    }else{
         $("#particulars button").show();
    }
    if($("#particulars button").attr("marker")==0){
        $("#particulars button").hide();
    }else{
         $("#particulars button").show();
    }
    if($("#detailsBox>h2 a").attr("marker")==0){
        $("#detailsBox>h2 a").show().css("float","right");
    }else{
        $("#detailsBox>h2 a").hide();
    }
}